import { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { setPageTitle } from '../../features/common/headerSlice'
import MineUser from '../../features/mineUser'
import UserService from '../../app/services/userService'
import { setUserInfo } from '../../app/store/userinfoSlice'

function MineUserPage(){
    const dispatch = useDispatch()

    useEffect(() => {
        dispatch(setPageTitle({ title : "我的考生列表"}))
      }, [])

      UserService.autoLogin().then(response => {
        console.log(response)
        if (response.success) {
            localStorage.setItem("token",`Bearer  ${response.data.token}`)
            const uerInfo = {...response.data,ticket: new Date().getTime()}
            dispatch(setUserInfo(uerInfo))
        } else {
          localStorage.removeItem("token")
          window.location.href = '/login'
        }
    }).catch(error => {
        localStorage.removeItem("token")
        window.location.href = '/login'
    })


    return(
        <MineUser />
    )
}

export default MineUserPage